package com.nhncorp.mojo.jumble;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

public class CollectErrorStream extends AbstractJumbleMojo implements Runnable {
	private InputStream inputStream;
	private boolean isXmlOutput;
	public static StringBuffer verbose;

	public CollectErrorStream(InputStream is, boolean isXmlOutput) {
		verbose = new StringBuffer();
		
		this.inputStream = is;
		this.isXmlOutput = isXmlOutput;
	}

	public void run() {
		InputStreamReader isr = new InputStreamReader(inputStream);
		BufferedReader br = new BufferedReader(isr);
		String line;
		
		try {
			while ((line = br.readLine()) != null) {
				getLog().info(line);

				if (isXmlOutput) {
					if (line != null)
						verbose.append(line).append("\r\n");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
	}
}